package com.sy.service.impl;

import com.sy.dto.EquipStateDto;
import com.sy.dto.EquipmentDto;
import com.sy.entity.Equipment;
import com.sy.mapper.EquipmentMapper;
import com.sy.service.EquipmentService;
import com.sy.vo.EquipmentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @author easonsy
 * @Description
 * @createTime 2022/06/25 15:57:00
 */
@Service
public class EquipmentServiceImpl implements EquipmentService {
    @Autowired
    private EquipmentMapper equipmentMapper;

    @Override
    public List<Equipment> showAllEquipment() {
        return equipmentMapper.showAllEquipments();
    }

    @Override
    public boolean alterEquipmentState(Integer id, Integer stateId) {
        if (equipmentMapper.changeState(stateId, id) > 0) {
            return true;
        } else {
            return false;

        }
//        return equipmentMapper.changeState(stateId,id);
    }

    @Override
    public boolean addEquipment(EquipmentVo equipmentVo) {
        Integer id = equipmentMapper.addEquipment(equipmentVo);
        if (Objects.nonNull(equipmentMapper.selectEquipmentById(id))) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean delEquipment(Integer id) {
        if (equipmentMapper.delEquipment(id) > 0) {
            return true;
        }
        return false;
    }

    @Override
    public List<EquipStateDto> showEquipState() {
        return equipmentMapper.showEquipState();
    }

    @Override
    public List<Equipment> findAllEquipsByName(EquipmentVo equipmentVo) {
        return equipmentMapper.selectAllEquipsByName(equipmentVo);
    }

}
